﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using MySql.Data.MySqlClient;
using System.Data;

namespace GrainManage.Data.Provider
{
    public class MySqlProvider : ProviderBase
    {
        public MySqlProvider(string connectionString) : base(connectionString) { }

        public override DbConnection Connection
        {
            get
            {
                return new MySqlConnection(ConnectionString);
            }
        }

        public override DbCommand GetCommand(string cmdText, DbConnection connection)
        {
            var cmd = new MySqlCommand(cmdText, connection as MySqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            return cmd;
        }

        public override DbDataAdapter GetAdapter(string selectCmdText)
        {
            var cmd = GetCommand(selectCmdText, Connection);
            return new MySqlDataAdapter(cmd as MySqlCommand);
        }

        public override DbParameter GetDbParameter(string paraName, object value, ParameterDirection direction = ParameterDirection.Input)
        {
            var parameter = new MySqlParameter(paraName, value);
            parameter.Direction = direction;
            return parameter;
        }
    }
}
